//
//  PopViewController.swift
//  Popping
//
//  Created by CraigGrummitt on 14/09/2014.
//  Copyright (c) 2014 CraigGrummitt. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON

protocol PopViewControllerDelegate {
    func closePop(sender:AnyObject)
}

class PopViewController: UIViewController {
    
  
    @IBOutlet weak var productImae: UIImageView!
    @IBOutlet weak var titleTxt: UILabel!
    @IBOutlet weak var contentTxt: UILabel!
    @IBOutlet weak var clickbutton: UIButton!
    
    var popview:ProductPayController?
    
    var productImageUrl:String?
    var productTxt1:String?
    var productTxt2:String?
    var productTxt3:String?
    var productType:String?
    var productID:String?
    
    @IBAction func onActioncli(sender: AnyObject) {
        
        if (productType == "1")  {
            //中了实物奖品，直接跳转到支付页面
            //ProductPay ProductPayController
            let sb = UIStoryboard(name: "Main", bundle: nil)
            popview = (sb.instantiateViewControllerWithIdentifier("ProductPay") as! ProductPayController)
            print(productID)
            popview?.productID = productID
            
            self.showViewController(popview!, sender: self)
        //    self.presentViewController(popview!, animated: true, completion: nil)
            
        }
    }
    var delegate:PopViewControllerDelegate?
    override func viewDidLoad() {
        super.viewDidLoad()
        
        print(productImageUrl!)
        Alamofire.request(.GET, productImageUrl!).response() {
            (_, _, data, _) in
            let image = UIImage(data: data! as NSData)
            self.productImae.image = image
        }
        
        titleTxt.text = productTxt1
        contentTxt.text = productTxt2
        print(productTxt3)
        clickbutton.setTitle(productTxt3, forState:UIControlState.Normal)
        //self.productImage.image = UIImage(named: productImageUrl!)
        // Do any additional setup after loading the view.
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func clickCloseButton(sender: AnyObject) {
        self.delegate?.closePop(self)
    }

    
    /*
    // MARK: - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    }
    */
    
}
